<extend name="./Common/View/Public/base.html"/>
<block name="main">
    <div class="layui-tab layui-tab-brief" lay-filter="user">
        <ul class="layui-tab-title" id="LAY_mine">
            <li class="layui-this" lay-id="password">修改密码</li>
        </ul>
        <div class="layui-tab-content" style="padding: 20px 0;">
            <div class="layui-form layui-form-pane layui-tab-item layui-show">
                <form class="layui-form" method="post" action="" lay-filter="pageForm">
                    <div class="layui-form-item"><label for="oldpass" class="layui-form-label">当前密码</label>
                        <div class="layui-input-inline"><input type="password" id="oldpass" name="oldpass" required=""
                                                               lay-verify="required|length" minlength="6" maxlength="20"
                                                               autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item"><label for="newpass" class="layui-form-label">新密码</label>
                        <div class="layui-input-inline"><input type="password" id="newpass" name="newpass" required=""
                                                               lay-verify="required|length" minlength="6" maxlength="20"
                                                               autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">6到20个字符</div>
                    </div>
                    <div class="layui-form-item"><label for="repass" class="layui-form-label">确认密码</label>
                        <div class="layui-input-inline"><input type="password" id="repass" name="repass" required=""
                                                               lay-verify="required|length" minlength="6" maxlength="20"
                                                               autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <button class="layui-btn" key="set-mine" lay-filter="*" lay-submit="">确认修改</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</block>

<block name="script">
    <script>
        layui.use(['form', 'layer', 'element', 'jquery'], function () {
            layui.form.on('submit(pageForm)', function (data) {
                if (data.field.newpass != data.field.repass) {
                    app.error('再次输入的密码不一致!');
                    return false;
                }
                var param = {};
                param.oldpass = $.md5(data.field.oldpass + app.md5_salt);
                param.newpass = $.md5(data.field.newpass + app.md5_salt);
                app.post('sys/user/password', param, function (response) {
                    if (response.error == '0') {
                        app.success(response.message);
                        window.location.reload(true);
                    } else {
                        app.error(response.message);
                    }
                });
                return false;
            });
        });
    </script>
    <script src="__JS__/jquery.md5.js"></script>
</block>